<?
	if($_SESSION['is_login'] != true){ header("Location: ".$root."/dang-nhap/");}
	
	if(isset($_SESSION['uid'])){$u_id = $_SESSION['uid'];}
	
	$mess = "";
	
	if(isset($_GET['friend_id'])){
	
		$friend_id = intval($_GET['friend_id']);
		
		if($friend_id == $u_id){reHome($urlHome);}
		$rs = $db->query("SELECT * FROM ".$prefix."nguoidung WHERE u_id = '".$friend_id."' AND u_banned = 1");
		if($db->num_rows($rs) != 0){
			$row = $db->fetch_array($rs);
			$friend_name = $row[u_name];
		}else{
			Redirect("Thành viên bạn muốn kết bạn đã bị khóa !",$urlHome);
		}
		
	}else{
		if( (isset($_GET['act'])) && ($_GET['act'] == 'ok') ){
			if(!isset($_GET['kb_uid'])){reHome($urlHome);}else{$kb_uid = $_GET['kb_uid'];}
			if(!isset($_GET['kb_friend_id'] )){reHome($urlHome);}else{$kb_friend_id = $_GET['kb_friend_id'];}

			$db->query("UPDATE ".$prefix."ketban SET kb_trangthai = 1 WHERE kb_uid = '".$kb_uid."' AND kb_friend_id = '".$kb_friend_id."'");
			
			$db->query("INSERT INTO ".$prefix."ketban(kb_uid,kb_friend_id,kb_trangthai) VALUES('".$_SESSION['uid']."','".$kb_uid."',1)");
			
			$mess = "<B>".tenNguoiDung($kb_uid)."</B> đã được thêm vào danh sách bạn bè của bạn !";
			
		}else{reHome($urlHome);}
	}
	
	
	
	
	
	if(isset($_POST['submit'])){
		$friend_id = $_POST['friend_id'];
		$link= "<br><br><b>VNSS Notice : </b> <br>Mời bạn click vào link sau để đồng ý kết bạn với ".$_SESSION['uname'].": <a href=\"".$homepage."index.php?mod=ketban&act=ok&kb_uid=".$u_id."&kb_friend_id=".$friend_id."\" target=\"_blank\">".$homepage."index.php?mod=ketban&act=ok&kb_uid=".$u_id."&kb_friend_id=".$friend_id."</a>";
		
		$txtMessage = $_POST['txtMessage'] . $link;
		$tnr_tieude = "Yêu cầu kết bạn của ".$_SESSION['uname']."";
		//
		///
		$db->query("INSERT INTO ".$prefix."ketban(kb_uid,kb_friend_id,kb_trangthai) VALUES('".$u_id."','".$friend_id."',0)");
		$db->query("INSERT INTO ".$prefix."tinnhanrieng(tnr_tieude,tnr_noidung,tnr_nguoinhan,tnr_nguoigui,tnr_thoigian,tnr_danhdau,tnr_tinhtrang) VALUES('".$tnr_tieude."','".$txtMessage."','".$friend_id."','".$u_id."',now(),0,0)");
		//
		
		$mess = "Gửi yêu cầu kết bạn thành công ! Vui lòng chờ người dùng chấp nhận.";
	}
?>
<div id="linkPath">
        

<div class="linkPath">
    <div class="corner-round-01-top-right">
        <div class="corner-round-01-top-left">
            <div class="corner-round-01-top-bg"></div>
        </div>
    </div>
    <div class="corner-round-01-body">    
        
		<?
			file_exist('includes/inc_thong_tin_rieng.php');
			include('includes/inc_thong_tin_rieng.php');	
		?>
		
        <div style="clear: both;"></div>

    </div>
    <div class="corner-round-01-bottom-right">
        <div class="corner-round-01-bottom-left">
            <div class="corner-round-01-bottom-bg"></div>
        </div>
    </div>   
</div>
    </div>
    <!-- Main Page-Content { -->
    <div id="page-content">
        

<div id="userAddFriend">
    <div class="corner-round-02-top-right">
        <div class="corner-round-02-top-left">
            <div class="corner-round-02-top-bg"></div>
        </div>
    </div>
    
    <div class="corner-round-02-body">  
	    <div class="userAddFriend" style="overflow: hidden; height: auto;">

	        <h3 class="form-header">Kết bạn</h3>
	        <div id="ctl00_idMainHolder_idUserAddFriend_jsError"></div>
	        <div id="error" class="form-error-group"></div>
		    <p class="form-line"></p>	
			<? if($mess == ""){ ?>
			
		    <div class="field">
			    <label>Tên bạn muốn kết</label><?=$friend_name?>
		    </div>
<form action="" name="frmKetBan" id="frmKetBan" method="post">
		    <div class="field">

			    <label>Thông điệp</label>
			    <textarea id="txtMessage" name="txtMessage" rows="5" cols="37">Mình muốn kết bạn với bạn, bạn đồng ý nhé!</textarea>
		    </div>
		    
		    <div class="field">
			    <label>&nbsp;</label>
				<input type="hidden" name="friend_id" value="<?=$friend_id?>" />
				<input type="hidden" name="submit" id="submit" value="submit" />
			    <input id="accept" name="accept" class="img" src="<?=$root?>/themes/images/form/button-sent.jpg" type="image">
		    </div>
</form>
		<? }else{ ?>
			<div class="field">
			<label>&nbsp;</label>
			<span style="font-weight:bold; color:#FF0000"><?=$mess?></span>
			</div>	    
		<? } ?>
		
        </div>

    </div> 
       
    <div class="corner-round-02-bottom-right">
        <div class="corner-round-02-bottom-left">
            <div class="corner-round-02-bottom-bg"></div>
        </div>
    </div>   
</div>
        <div style="clear: both;">        
    </div>
    <!-- } Main Page-Content -->
</
                 
            </div>
